/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2023 All Rights Reserved.
 */
package com.example.spider.config;

import com.example.spider.config.support.annotation.SpiderHandlerAdvice;
import com.example.spider.config.support.annotation.SpiderResultExHandler;
import com.example.spider.provider.m3u8.handler.M3u8FirstHandler;
import com.example.spider.task.AbstractSpiderTask;
import com.example.spider.task.Task;
import lombok.extern.slf4j.Slf4j;

/**
 * ExceptionHandlerExceptionResolver#afterPropertiesSet  initExceptionHandlerAdviceCache()
 * 扫描 ControllerAdvice ExceptionHandlerMethodResolver 解析被@ExceptionHandler注解的方法，保存异常类及对应的异处常理方法<exceptionType, method>。
 *
 * @author lym
 */
@Slf4j
@SpiderHandlerAdvice(basePackageClasses = M3u8FirstHandler.class)
public class ExceptionHandlerConfiguration {

    /**
     * @see com.example.spider.provider.m3u8.handler.M3u8FirstHandler#handle
     */
    @SpiderResultExHandler
    public <T> T handleM3u8FirstFail(AbstractSpiderTask<T> task, Exception e) {
        log.error("handler process FAIL task(url={})", task.getUrl(), e);
        return null;
    }

    @SpiderResultExHandler
    public <T> T defaultExHandler(AbstractSpiderTask<T> task, Throwable t) {
        log.error("handler process FAIL task({})", task.getUrl(), t);
        return null;
    }

    // @SpiderExHandler
    public <T> T handle(Task<T> task, T spiderResult, Exception e) {

        return null;
    }

}